.class Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;
.super Ljava/lang/Object;
.source "LocationValet.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$1;,
        Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ILocationValetListener;,
        Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ValetLocationListener;
    }
.end annotation


# static fields
.field private static final TWO_MINUTES:I = 0x1d4c0


# instance fields
.field private mHasGpsPermission:Z

.field private mHasNetworkPermission:Z

.field private mLastGoodLocation:Landroid/location/Location;

.field private mListener:Landroid/location/LocationListener;

.field private final mLocationManager:Landroid/location/LocationManager;

.field private final mValetListener:Ljava/lang/ref/Reference;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/lang/ref/Reference",
            "<",
            "Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ILocationValetListener;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method constructor <init>(Landroid/content/Context;Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ILocationValetListener;)V
    .locals 4
    .parameter "context"
    .parameter "listener"

    .prologue
    const/4 v1, 0x1

    const/4 v2, 0x0

    .line 49
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 50
    new-instance v0, Ljava/lang/ref/WeakReference;

    invoke-direct {v0, p2}, Ljava/lang/ref/WeakReference;-><init>(Ljava/lang/Object;)V

    iput-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mValetListener:Ljava/lang/ref/Reference;

    .line 52
    const-string v0, "location"

    invoke-virtual {p1, v0}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/location/LocationManager;

    iput-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLocationManager:Landroid/location/LocationManager;

    .line 53
    new-instance v0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ValetLocationListener;

    const/4 v3, 0x0

    invoke-direct {v0, p0, v3}, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ValetLocationListener;-><init>(Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$1;)V

    iput-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mListener:Landroid/location/LocationListener;

    .line 55
    const-string v0, "android.permission.ACCESS_COARSE_LOCATION"

    invoke-virtual {p1, v0}, Landroid/content/Context;->checkCallingOrSelfPermission(Ljava/lang/String;)I

    move-result v0

    if-nez v0, :cond_0

    move v0, v1

    :goto_0
    iput-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mHasNetworkPermission:Z

    .line 56
    const-string v0, "android.permission.ACCESS_FINE_LOCATION"

    invoke-virtual {p1, v0}, Landroid/content/Context;->checkCallingOrSelfPermission(Ljava/lang/String;)I

    move-result v0

    if-nez v0, :cond_1

    :goto_1
    iput-boolean v1, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mHasGpsPermission:Z

    .line 57
    return-void

    :cond_0
    move v0, v2

    .line 55
    goto :goto_0

    :cond_1
    move v1, v2

    .line 56
    goto :goto_1
.end method

.method static synthetic access$100(Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;)Landroid/location/Location;
    .locals 1
    .parameter "x0"

    .prologue
    .line 36
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLastGoodLocation:Landroid/location/Location;

    return-object v0
.end method

.method static synthetic access$200(Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;Landroid/location/Location;Landroid/location/Location;)Z
    .locals 1
    .parameter "x0"
    .parameter "x1"
    .parameter "x2"

    .prologue
    .line 36
    invoke-direct {p0, p1, p2}, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->isBetterLocation(Landroid/location/Location;Landroid/location/Location;)Z

    move-result v0

    return v0
.end method

.method private isBetterLocation(Landroid/location/Location;Landroid/location/Location;)Z
    .locals 14
    .parameter "location"
    .parameter "currentBestLocation"

    .prologue
    .line 122
    if-nez p2, :cond_0

    .line 124
    const/4 v10, 0x1

    .line 159
    :goto_0
    return v10

    .line 128
    :cond_0
    invoke-virtual {p1}, Landroid/location/Location;->getTime()J

    move-result-wide v10

    invoke-virtual/range {p2 .. p2}, Landroid/location/Location;->getTime()J

    move-result-wide v12

    sub-long v8, v10, v12

    .line 129
    .local v8, timeDelta:J
    const-wide/32 v10, 0x1d4c0

    cmp-long v10, v8, v10

    if-lez v10, :cond_1

    const/4 v6, 0x1

    .line 130
    .local v6, isSignificantlyNewer:Z
    :goto_1
    const-wide/32 v10, -0x1d4c0

    cmp-long v10, v8, v10

    if-gez v10, :cond_2

    const/4 v7, 0x1

    .line 131
    .local v7, isSignificantlyOlder:Z
    :goto_2
    const-wide/16 v10, 0x0

    cmp-long v10, v8, v10

    if-lez v10, :cond_3

    const/4 v4, 0x1

    .line 135
    .local v4, isNewer:Z
    :goto_3
    if-eqz v6, :cond_4

    .line 136
    const/4 v10, 0x1

    goto :goto_0

    .line 129
    .end local v4           #isNewer:Z
    .end local v6           #isSignificantlyNewer:Z
    .end local v7           #isSignificantlyOlder:Z
    :cond_1
    const/4 v6, 0x0

    goto :goto_1

    .line 130
    .restart local v6       #isSignificantlyNewer:Z
    :cond_2
    const/4 v7, 0x0

    goto :goto_2

    .line 131
    .restart local v7       #isSignificantlyOlder:Z
    :cond_3
    const/4 v4, 0x0

    goto :goto_3

    .line 138
    .restart local v4       #isNewer:Z
    :cond_4
    if-eqz v7, :cond_5

    .line 139
    const/4 v10, 0x0

    goto :goto_0

    .line 143
    :cond_5
    invoke-virtual {p1}, Landroid/location/Location;->getAccuracy()F

    move-result v10

    invoke-virtual/range {p2 .. p2}, Landroid/location/Location;->getAccuracy()F

    move-result v11

    sub-float/2addr v10, v11

    float-to-int v0, v10

    .line 144
    .local v0, accuracyDelta:I
    if-lez v0, :cond_6

    const/4 v2, 0x1

    .line 145
    .local v2, isLessAccurate:Z
    :goto_4
    if-gez v0, :cond_7

    const/4 v3, 0x1

    .line 146
    .local v3, isMoreAccurate:Z
    :goto_5
    const/16 v10, 0xc8

    if-le v0, v10, :cond_8

    const/4 v5, 0x1

    .line 149
    .local v5, isSignificantlyLessAccurate:Z
    :goto_6
    invoke-virtual {p1}, Landroid/location/Location;->getProvider()Ljava/lang/String;

    move-result-object v10

    invoke-virtual/range {p2 .. p2}, Landroid/location/Location;->getProvider()Ljava/lang/String;

    move-result-object v11

    invoke-direct {p0, v10, v11}, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->isSameProvider(Ljava/lang/String;Ljava/lang/String;)Z

    move-result v1

    .line 152
    .local v1, isFromSameProvider:Z
    if-eqz v3, :cond_9

    .line 153
    const/4 v10, 0x1

    goto :goto_0

    .line 144
    .end local v1           #isFromSameProvider:Z
    .end local v2           #isLessAccurate:Z
    .end local v3           #isMoreAccurate:Z
    .end local v5           #isSignificantlyLessAccurate:Z
    :cond_6
    const/4 v2, 0x0

    goto :goto_4

    .line 145
    .restart local v2       #isLessAccurate:Z
    :cond_7
    const/4 v3, 0x0

    goto :goto_5

    .line 146
    .restart local v3       #isMoreAccurate:Z
    :cond_8
    const/4 v5, 0x0

    goto :goto_6

    .line 154
    .restart local v1       #isFromSameProvider:Z
    .restart local v5       #isSignificantlyLessAccurate:Z
    :cond_9
    if-eqz v4, :cond_a

    if-nez v2, :cond_a

    .line 155
    const/4 v10, 0x1

    goto :goto_0

    .line 156
    :cond_a
    if-eqz v4, :cond_b

    if-nez v5, :cond_b

    if-eqz v1, :cond_b

    .line 157
    const/4 v10, 0x1

    goto :goto_0

    .line 159
    :cond_b
    const/4 v10, 0x0

    goto :goto_0
.end method

.method private isSameProvider(Ljava/lang/String;Ljava/lang/String;)Z
    .locals 1
    .parameter "provider1"
    .parameter "provider2"

    .prologue
    .line 164
    if-nez p1, :cond_1

    .line 165
    if-nez p2, :cond_0

    const/4 v0, 0x1

    .line 167
    :goto_0
    return v0

    .line 165
    :cond_0
    const/4 v0, 0x0

    goto :goto_0

    .line 167
    :cond_1
    invoke-virtual {p1, p2}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    goto :goto_0
.end method


# virtual methods
.method startAquire(Ljava/lang/Boolean;)Ljava/lang/Boolean;
    .locals 6
    .parameter "immediateResult"

    .prologue
    const/4 v4, 0x0

    .line 60
    invoke-virtual {p1}, Ljava/lang/Boolean;->booleanValue()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 61
    iget-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mHasGpsPermission:Z

    if-eqz v0, :cond_1

    .line 62
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLocationManager:Landroid/location/LocationManager;

    const-string v1, "gps"

    invoke-virtual {v0, v1}, Landroid/location/LocationManager;->getLastKnownLocation(Ljava/lang/String;)Landroid/location/Location;

    move-result-object v0

    invoke-virtual {p0, v0}, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->updateValetListeners(Landroid/location/Location;)V

    .line 68
    :cond_0
    :goto_0
    sget-object v0, Landroid/os/Build;->FINGERPRINT:Ljava/lang/String;

    const-string v1, "generic"

    invoke-virtual {v0, v1}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v0

    if-nez v0, :cond_2

    iget-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mHasNetworkPermission:Z

    if-eqz v0, :cond_2

    .line 69
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLocationManager:Landroid/location/LocationManager;

    const-string v1, "network"

    const-wide/16 v2, 0xbb8

    iget-object v5, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mListener:Landroid/location/LocationListener;

    invoke-virtual/range {v0 .. v5}, Landroid/location/LocationManager;->requestLocationUpdates(Ljava/lang/String;JFLandroid/location/LocationListener;)V

    .line 75
    :goto_1
    const/4 v0, 0x1

    invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v0

    :goto_2
    return-object v0

    .line 63
    :cond_1
    iget-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mHasNetworkPermission:Z

    if-eqz v0, :cond_0

    .line 64
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLocationManager:Landroid/location/LocationManager;

    const-string v1, "network"

    invoke-virtual {v0, v1}, Landroid/location/LocationManager;->getLastKnownLocation(Ljava/lang/String;)Landroid/location/Location;

    move-result-object v0

    invoke-virtual {p0, v0}, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->updateValetListeners(Landroid/location/Location;)V

    goto :goto_0

    .line 70
    :cond_2
    iget-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mHasGpsPermission:Z

    if-eqz v0, :cond_3

    .line 71
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLocationManager:Landroid/location/LocationManager;

    const-string v1, "gps"

    const-wide/16 v2, 0x0

    iget-object v5, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mListener:Landroid/location/LocationListener;

    invoke-virtual/range {v0 .. v5}, Landroid/location/LocationManager;->requestLocationUpdates(Ljava/lang/String;JFLandroid/location/LocationListener;)V

    goto :goto_1

    .line 73
    :cond_3
    const/4 v0, 0x0

    invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v0

    goto :goto_2
.end method

.method stopAquire()V
    .locals 2

    .prologue
    .line 79
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLocationManager:Landroid/location/LocationManager;

    iget-object v1, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mListener:Landroid/location/LocationListener;

    invoke-virtual {v0, v1}, Landroid/location/LocationManager;->removeUpdates(Landroid/location/LocationListener;)V

    .line 80
    return-void
.end method

.method updateValetListeners(Landroid/location/Location;)V
    .locals 2
    .parameter "l"

    .prologue
    .line 83
    iput-object p1, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mLastGoodLocation:Landroid/location/Location;

    .line 84
    iget-object v1, p0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet;->mValetListener:Ljava/lang/ref/Reference;

    invoke-virtual {v1}, Ljava/lang/ref/Reference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ILocationValetListener;

    .line 85
    .local v0, locationValetListener:Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ILocationValetListener;
    if-eqz v0, :cond_0

    .line 86
    invoke-interface {v0, p1}, Lcom/burstly/lib/component/networkcomponent/millennial/LocationValet$ILocationValetListener;->onBetterLocationFound(Landroid/location/Location;)V

    .line 88
    :cond_0
    return-void
.end method
